package cn.com.sina.finance.todolist.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.imageview.ShapeableImageView;

import cn.com.sina.finance.todolist.R;
import cn.com.sina.finance.todolist.base.Tab;

/**
 * @author yuebo
 * @date 2023/7/28
 */
public class MainTabView extends FrameLayout {

    private TextView tvTitle;
    private ShapeableImageView imageView;

    public MainTabView(@NonNull Context context) {
        this(context, null);
    }

    public MainTabView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MainTabView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.view_main_tab, this);
        tvTitle = findViewById(R.id.tvMainTab);
        imageView = findViewById(R.id.ivMainTab);
    }

    public void init(@NonNull Tab tab) {
        tvTitle.setText(tab.getTitle());
        String tabId = tab.getTabId();
        if (MainTabId.TODO_LIST.equals(tabId)) {
            imageView.setImageResource(R.drawable.selector_main_tab_news);
        } else if (MainTabId.ADD_TODO.equals(tabId)) {
            imageView.setImageResource(R.drawable.selector_main_tab_zx);
        } else if (MainTabId.USER.equals(tabId)) {
            imageView.setImageResource(R.drawable.selector_main_tab_mine);
        }
    }
}
